package com.mebs.model.service.visa;

import com.mebs.model.Country;

import javax.persistence.*;

import static org.hibernate.proxy.HibernateProxyHelper.getClassWithoutInitializingProxy;

/**
 * Created by Sergey Prasolov, sap@jensentechnologies.com
 * Date: Mar 10, 2006, 6:42:09 PM
 */
@Entity()
@Table(name = "VISA_ACTION")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "ActionType", discriminatorType = DiscriminatorType.STRING)
public abstract class AbstractCountryAction {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "Id")
    private Long id;

    @ManyToOne(optional = false)
    @JoinColumn(name = "CountryId")
    private Country country;

    @Column(name = "Action", nullable = false, length = 250)
    private String action;

    @Column(name = "Description", nullable = true, length = 1024)
    private String description;

    @Column(name = "Responsibility", nullable = false)
    private Integer responsibility;


    /**
     * **********************
     * Getters-setters
     * ***********************
     */

    public Long getId()
    {
        return id;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    public Country getCountry()
    {
        return country;
    }

    public void setCountry(Country country)
    {
        this.country = country;
    }

    public String getAction()
    {
        return action;
    }

    public void setAction(String action)
    {
        this.action = action;
    }

    public String getDescription()
    {
        return description;
    }

    public void setDescription(String description)
    {
        this.description = description;
    }

    public Integer getResponsibility()
    {
        return responsibility;
    }

    public void setResponsibility(Integer responsibility)
    {
        this.responsibility = responsibility;
    }

    @Override
    public String toString()
    {
        return this.action;
    }

    @Override
    public int hashCode()
    {
        if (id == null) return super.hashCode();
        return id.hashCode();
    }

    @Override
    public boolean equals(Object o)
    {
        if (o == null) return false;
        if (this == o) return true;
        if (id == null) return false;
        if (getClassWithoutInitializingProxy(o) != getClassWithoutInitializingProxy(this) &&
            ! getClassWithoutInitializingProxy(o).isAssignableFrom(AbstractCountryAction.class))
            return false;
        final AbstractCountryAction that = (AbstractCountryAction) o;
        return id.equals(that.getId());
    }

}
